package de.kraenksoft.android.cinemaExample.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtil {
	public static boolean datesOnSameDay(Date date1, Date date2) {
		Calendar cal1 = new GregorianCalendar();
		Calendar cal2 = new GregorianCalendar();

		cal1.setTime(date1);
		cal2.setTime(date2);

		if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR))
			return false;
		if (cal1.get(Calendar.DAY_OF_YEAR) != cal2.get(Calendar.DAY_OF_YEAR))
			return false;

		return true;
	}

	//TODO: Tried to use the ICU library but the jar has a size of 16MB. We need to use internationalization here.
	private static String[] dayNames = { "Mo", "Di", "Mi", "Do", "Fr", "Sa",
			"So" };

	public static String getShortDayNameForDate(Date date) {
		Calendar cal = new GregorianCalendar();
		cal.setTime(date);
		int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
		switch (dayOfWeek) {
		case Calendar.MONDAY:
			return dayNames[0];
		case Calendar.TUESDAY:
			return dayNames[1];
		case Calendar.WEDNESDAY:
			return dayNames[2];
		case Calendar.THURSDAY:
			return dayNames[3];
		case Calendar.FRIDAY:
			return dayNames[4];
		case Calendar.SATURDAY:
			return dayNames[5];
		default:
			return dayNames[6];
		}
	}
	
	public static String getDayTitleForDate(Date date){
		Calendar cal = GregorianCalendar.getInstance();
		if(datesOnSameDay(date, cal.getTime())) return "Heute";
		cal.add(Calendar.DAY_OF_YEAR, 1);
		if(datesOnSameDay(date, cal.getTime())) return "Morgen";
		return getShortDayNameForDate(date);
	}

}
